package cn.edu.sdjzu.xg.eagle.bysj.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.WenjianfenleiEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.WenjianfenleiView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.WenjianfenleiService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;



@RestController
@RequestMapping("/wenjianfenlei")
public class WenjianfenleiController {
    @Autowired
    private WenjianfenleiService wenjianfenleiService;





    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, WenjianfenleiEntity wenjianfenlei,
                  HttpServletRequest request){
        EntityWrapper<WenjianfenleiEntity> ew = new EntityWrapper<WenjianfenleiEntity>();



        PageUtils page = wenjianfenleiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjianfenlei), params), params));
        return R.ok().put("data", page);
    }


    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,WenjianfenleiEntity wenjianfenlei,
                  HttpServletRequest request){
        EntityWrapper<WenjianfenleiEntity> ew = new EntityWrapper<WenjianfenleiEntity>();

        PageUtils page = wenjianfenleiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjianfenlei), params), params));
        return R.ok().put("data", page);
    }

    @RequestMapping("/lists")
    public R list( WenjianfenleiEntity wenjianfenlei){
        EntityWrapper<WenjianfenleiEntity> ew = new EntityWrapper<WenjianfenleiEntity>();
        ew.allEq(MPUtil.allEQMapPre( wenjianfenlei, MPUtil.camelToSnake("wenjianfenlei")));
        return R.ok().put("data", wenjianfenleiService.selectListView(ew));
    }

    @RequestMapping("/query")
    public R query(WenjianfenleiEntity wenjianfenlei){
        EntityWrapper< WenjianfenleiEntity> ew = new EntityWrapper< WenjianfenleiEntity>();
        ew.allEq(MPUtil.allEQMapPre( wenjianfenlei, MPUtil.camelToSnake("wenjianfenlei")));
        WenjianfenleiView wenjianfenleiView =  wenjianfenleiService.selectView(ew);
        return R.ok("查询文件分类成功").put("data", wenjianfenleiView);
    }

    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        WenjianfenleiEntity wenjianfenlei = wenjianfenleiService.selectById(id);
        wenjianfenlei = wenjianfenleiService.selectView(new EntityWrapper<WenjianfenleiEntity>().eq("id", id));
        return R.ok().put("data", wenjianfenlei);
    }

    @IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        WenjianfenleiEntity wenjianfenlei = wenjianfenleiService.selectById(id);
        wenjianfenlei = wenjianfenleiService.selectView(new EntityWrapper<WenjianfenleiEntity>().eq("id", id));
        return R.ok().put("data", wenjianfenlei);
    }

    @RequestMapping("/save")
    @SysLog("新增文件分类")
    public R save(@RequestBody WenjianfenleiEntity wenjianfenlei, HttpServletRequest request){
        //ValidatorUtils.validateEntity(wenjianfenlei);
        wenjianfenleiService.insert(wenjianfenlei);
        return R.ok();
    }
    @SysLog("新增文件分类")
    @RequestMapping("/add")
    public R add(@RequestBody WenjianfenleiEntity wenjianfenlei, HttpServletRequest request){
        //ValidatorUtils.validateEntity(wenjianfenlei);
        wenjianfenleiService.insert(wenjianfenlei);
        return R.ok();
    }
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改文件分类")
    public R update(@RequestBody WenjianfenleiEntity wenjianfenlei, HttpServletRequest request){
        //ValidatorUtils.validateEntity(wenjianfenlei);
        wenjianfenleiService.updateById(wenjianfenlei);//全部更新
        return R.ok();
    }

    @RequestMapping("/delete")
    @SysLog("删除文件分类")
    public R delete(@RequestBody Long[] ids){
        wenjianfenleiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}
